//
//  NoticeView.m
//  KingSelected
//
//  Created by 杨鹏 on 2023/11/3.
//

#import "NoticeView.h"
#import "NoticeBarrageView.h"

@interface NoticeView ()

@property (nonatomic, assign) NSInteger index;
@property (nonatomic, strong) UIView *leftv;
@end

@implementation NoticeView

- (void)setTitleArr:(NSArray *)titleArr {
    _titleArr = titleArr;
    [self showBarrage];
}

- (void)initViews {
    self.backgroundColor = kRGB(0xFEF9E0);
    
    [self addSubview:self.leftv];
    
    UIImageView *laba = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"laba"]];
    [self.leftv addSubview:laba];
    [laba mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(14);
        make.centerY.mas_equalTo(0);
        make.leading.mas_equalTo(16);
    }];
}

- (UIView *)leftv {
    if (!_leftv) {
        _leftv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 36, 28)];
       _leftv.backgroundColor = kRGB(0xFEF9E0);
    }
    return _leftv;
}

- (void)showBarrage {
    if (self.titleArr.count == self.index) {
        self.index = 0;
    }
    NoticeBarrageView *barrage = [[NoticeBarrageView alloc] initWithFrame:CGRectMake(kWidthForScreen, 0, kWidthForScreen-36, 28)];
    barrage.backgroundColor = [UIColor clearColor];
    [self addSubview:barrage];
    [self bringSubviewToFront:self.leftv];
    @weakify(self)
    [barrage setAnimateCompleteBlock:^{
     @strongify(self)
        self.index++;
        [self showBarrage];
    }];
    barrage.text = self.titleArr[self.index];
}

@end
